package com.tk.demo.fwk.rdb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnect {
	static Connection con = null;
	
	/*static{
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			 System.out.println("开始尝试连接数据库！");
			 String url = "jdbc:oracle:" + "thin:@127.0.0.1:1521:ORCL";// 127.0.0.1是本机地址，XE是精简版Oracle的默认数据库名
			 String user = "dba_tank";// 用户名,系统默认的账户名
			 String password = "z123456";// 你安装时选设置的密码
			 con = DriverManager.getConnection(url, user, password);// 获取连接
		} catch (ClassNotFoundException e ) {
			e.printStackTrace();
		}catch (SQLException e  ) {
			e.printStackTrace();
		}// 加载Oracle驱动程序// 加载Oracle驱动程序
	}*/
	public static Connection getConnect(){
		if(con == null) {
			con = getMysqlConnect();
		}
		return con;
	}
	
	public static Connection getMysqlConnect() {
		 String driver = "com.mysql.jdbc.Driver";

         // URL指向要访问的数据库名scutcs
         String url = "jdbc:mysql://127.0.0.1:3306/demo";

         // MySQL配置时的用户名
         String user = "root"; 

         // MySQL配置时的密码
         String password = "";

         try { 
          // 加载驱动程序
          Class.forName(driver);

          // 连续数据库
         return DriverManager.getConnection(url, user, password);
         }catch (Exception e) {
			// TODO: handle exception
		}
		return null;
    }
}
